/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package moonnms;

import moonnms.libs.config.*;
import java.net.InetAddress;
import java.util.HashMap;

import moonnms.libs.*;
import Devices.Switches.*;
import java.lang.reflect.Constructor;
import java.util.logging.Level;
import java.util.logging.Logger;
import moonnms.libs.interfaces.NMSSwitchContext;
/**
 *
 * @author Di_Moon
 */
public class MoonNMS {

    /**
     * @param args the command line arguments
     */
    public static void startXMLRPC() {
        try {
            System.out.println("* Creating xmlRPC server");
            byte[] localhost = {127, 0, 0, 1};
            InetAddress addr = InetAddress.getByAddress(localhost);
            xmlRPCServer rpc = new xmlRPCServer(5080, addr);
            
            rpc.start();
            System.out.println("Now accepting requests. (Halt program to stop.)");
        } catch (Exception e) {
            System.out.println(e.toString());
        }
        
    }
    
    private static void telnetExample() {
        System.out.println("Connecting....");
        libNMSTelnetClient telnet = new libNMSTelnetClient("rt062.luglink.net", 23);
        telnet.setMorePattern(")---", " ");

        telnet.login("di_moon", "mUkusi7");
        String bgp = telnet.sendCommand("show bgp summary");
        
        System.out.println(bgp);
        
        telnet.disconnect();        
    }
    
    private static void sshExample() {
        System.out.println("SSH Example Connecting...");
        libNMSSSHClient ssh = new libNMSSSHClient("rt061.luglink.net", 22);
        ssh.login("di_moon", "mUkusi7");
        String strResult = ssh.sendCommand("show bgp summary");
        ssh.disconnect();
        
        System.out.println(strResult);
    }
    
    private static void snmpExample() {
        System.out.println("Snmp Example");
        libNMSSNMPClient snmp = new libNMSSNMPClient("sw042.luglink.net", "cyvgHJ");
        
//        String sysname = snmp.getString(".1.3.6.1.2.1.17.7.1.2.2.1.2");
//        long num = snmp.getLong(".1.3.6.1.2.1.2.2.1.13.24");
        HashMap<String, String> walk = snmp.walk(".1.3.6.1.2.1.17.7.1.2.2.1.2");
        System.out.println("value is "+walk);
    }
    
    public static void main(String[] args)  {
        try {
            //           NMSConfigDatabase cfg = new NMSConfigDatabase();
            //           System.getProperties().list(System.out);
            //        libNMSDBConnection db = new libNMSDBConnection();
                    
            /*        libNMSMacAddrTable table = new libNMSMacAddrTable();
                    table.put("112233445566", 1, 4);
                    table.put("122233445566", 2, 4);
                    table.put("00bbccddeeff", 3, 4);
                    table.put("012433445566", 1, 4);
                    
                    System.out.println(table.find("00bbccddeeff").mac);
            */
                    
                    NMSSwitchContext sw031 = (NMSSwitchContext)Class
                            .forName("Devices.Switches.dlinkDxSGeneric")
                            .getConstructor(String.class)
                            .newInstance("sw-dev1.luglink.net");
//                     =  c.newInstance("");
                    
            //        NMSSwitchContext sw031 = new dlinkDxSGeneric("sw042.luglink.net");
                    sw031.setUserPass("noc", "E032CC/47rus", "");
                    sw031.setSNMPCommunity("cyvgHJ", "cyvgHD");
/*                    System.out.println("Device Name : "+sw031.getDeviceName());
                    System.out.println("Firmware Version : "+sw031.getFirmwareVersion());
                    System.out.println("Hardware Version : "+sw031.getHardwareVersion());
                    System.out.println("Serial Number : "+sw031.getSerialNumber());
                    System.out.println("Sys Location : "+sw031.getSysLocation());
                    System.out.println("Sys Name : "+sw031.getSystemName());
*/
//                    System.out.println(sw031.getVlanPort(3));
/*                    HashMap<Integer, Integer> ports = new HashMap();
                    ports.put(20, 0);
                    ports.put(21, 0);
                    ports.put(25, 1);
                    ports.put(26, 1);
                    ports.put(27, 1);
                    ports.put(28, 1);
                    sw031.setVlan(3, "Super-V_la", ports);
                    */
//                    System.out.println(sw031.getPortsList(NMSSwitchContext.PORT_TYPE_L2VLAN));
//                    System.out.println(sw031.getMacAddressTable().getMacTable());
//                    sw031.deleteVlan(3);
            //        System.out.println(sw031.getConfiguration());
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}
